package com.gin.supermarket_inventory_system.commodity.dto.vo;

import com.gin.database.base.BaseVo;
import com.gin.supermarket_inventory_system.commodity.entity.CommodityProducerPo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @since : 2023/10/9 15:44
 * @author : ginstone
 * @version : v1.0.0
 **/
@Getter
@Setter
@Schema(description = "视图对象:")
public class CommodityProducerVo extends BaseVo {
    @Schema(description = "名称")
    String name;

    public CommodityProducerVo(CommodityProducerPo po) {
        // 复制Po的字段
        BeanUtils.copyProperties(po, this);
    }

    /**
     * 将持久对象列表转换为视图对象列表
     * @param data 持久对象列表
     * @return 视图对象列表
     */
    public static List<CommodityProducerVo> toVoList(List<CommodityProducerPo> data) {
        if (data == null) {
            return new ArrayList<>();
        }
        return data.stream().map(CommodityProducerVo::new).toList();
    }
}
